package com.qf.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.qf.entity.dto.Province;
import com.qf.mapper.ProvinceMapper;
import com.qf.service.redis.RedisService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProvinceService extends ServiceImpl<ProvinceMapper, Province> {

    @Resource
    private RedisService redisService;

    @Transactional
    public List<Province> queryProvince() {
        String province = (String) redisService.get("province");

        List<Province> list1 = null;
        if (province != null && !province.equals("")) {
            list1 = JSONObject.parseArray(province, Province.class);
            return list1;
        }
        list1 = this.baseMapper.queryProvince();
        String s = JSONObject.toJSONString(list1);
        redisService.set("province", s);
        return list1;
    }
}
